#! /usr/bin/env python

import wx

class RefactorExample(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, 'Refactor Example', size=(340, 200))
        panel = wx.Panel(self, wx.NewId())
        panel.SetBackgroundColour('White')
        prevButton = wx.Button(panel, wx.NewId(), '<<PREV', pos=(80,0))
        self.Bind(wx.EVT_BUTTON, self.OnPrev, prevButton)
        nextButton = wx.Button(panel, wx.NewId(), 'NEXT>>', pos=(160,0))
        self.Bind(wx.EVT_BUTTON, self.OnNext, nextButton)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        menuBar = wx.MenuBar()
        menu1 = wx.Menu()
        openMenuItem = menu1.Append(wx.NewId(), "&Open", "Open in status bar")
        self.Bind(wx.EVT_MENU, self.OnOpen, openMenuItem)
        quitMenuItem = menu1.Append(wx.NewId(), "&Quit", "Quit")
        self.Bind(wx.EVT_MENU, self.OnCloseWindow, quitMenuItem)
        menuBar.Append(menu1, "&File")
        menu2 = wx.Menu()
        copyItem = menu2.Append(wx.NewId(), "&Copy", "Copy")
        self.Bind(wx.EVT_MENU, self.OnCopy, copyItem)
        cutItem = menu2.Append(wx.NewId(), "C&ut", "Cut")
        self.Bind(wx.EVT_MENU, self.OnCut, cutItem)
        pasteItem = menu2.Append(wx.NewId(), "&Paste", "Paste")
        self.Bind(wx.EVT_MENU, self.OnPaste, pasteItem)
        menuBar.Append(menu2, "&Edit")
        self.SetMenuBar(menuBar)

        static = wx.StaticText(panel, wx.NewId(), "First Name", pos=(10,50))
        static.SetBackgroundColour('White')
        text = wx.TextCtrl(panel, wx.NewId(), "", size=(100,-1), pos=(80,50))

        static2 = wx.StaticText(panel, wx.NewId(), "Last Name", pos=(10,80))
        static2.SetBackgroundColour('White')
        text2 = wx.TextCtrl(panel, wx.NewId(), "", size=(100,-1), pos=(80,80))

        firstButton = wx.Button(panel, wx.NewId(), "FIRST")
        self.Bind(wx.EVT_BUTTON, self.OnFirst, firstButton)

        menu2.AppendSeparator()
        optItem = menu2.Append(wx.NewId(), "&Options...", "Display Opeions")
        self.Bind(wx.EVT_MENU, self.OnOptions, optItem)

        lastButton = wx.Button(panel, wx.NewId(), 'LAST', pos=(240, 0))
        self.Bind(wx.EVT_BUTTON, self.OnLast, lastButton)

    # Just grouping the empty event handkers together
    def OnPrev(self, event): pass
    def OnNext(self, event): pass
    def OnLast(self, event): pass
    def OnFirst(self, event): pass
    def OnOpen(self, event): pass
    def OnCopy(self, event): pass
    def OnCut(self, event): pass
    def OnPaste(self, event): pass
    def OnOptions(self, event): pass

    def OnCloseWindow(self, event):
        self.Destroy()
        
    def createButtonBarR1(self):
        firstButton = wx.Button(panel, wx.NewId(), 'FIRST')
        self.Bind(wx.EVT_BUTTON, self.OnFirst, firstButton)
        prevButton = wx.Button(panel, wx.NewId(), '<<PREV', pos=(80,0))
        self.Bind(wx.EVT_BUTTON, self.OnPrev, prevButton)
        nextButton = wx.Button(panel, wx.NewId(), 'NEXT>>', pos=(160,0))
        self.Bind(wx.EVT_BUTTON, self.OnNext, nextButton)
        lastButton = wx.Button(panel, wx.NewId(), 'LAST', pos=(240,0))
        self.Bind(wx.EVT_BUTTON, self.OnLast, lastButton)

    def createButtonBarR2(self, panel):
        self.buildOneButton(panel, "First", self.OnFirst)
        self.buildOneButton(panel, "<<PREV", self.OnPrev, (80,0))
        self.buildOneButton(panel, "NEXT>>", self.OnNext, (160,0))
        self.buildOneButton(panel, "Last", self.OnLast, (240,))

    def buildOneButton(self, parent, label, handler, pos=(0,0)):
        button = wx.Button(parent, wx.NewId(), label, pos)
        self.Bind(wx.EVT_BUTTON, handler, button)
        return button

    def buttonData(self):
        return (("First", self.OnFirst),
                ("<<PREV", self.OnPrev),
                ("NEXT>>", self.OnNext),
                ("Last", self.OnLast))
    
    def createButtonBar(self, panel, yPos=0):
        xPos = 0
        for eachLabel, eachHandler in self.buttonData():
            pos = (xPos, yPos)
            button = self.buildOneButton(panel, eachLabel, eachHandler, pos)
            xPos += button.GetSize().width

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = RefactorExample(None, wx.NewId())
    frame.Show()
    app.MainLoop()
